#include "stdafx.h"

#include "Resource.h"

#include <iostream>

using namespace std;

namespace GMotor
{
	Resource::Resource(std::string path)
	{
		this->initialized = false;
		this->path = path;

#ifdef WIN
		for (int pos = this->path.find('/'); pos>=0; pos = this->path.find('/'))
			this->path = this->path.replace(pos,1,"\\");
#else
		for (int pos = this->path.find('\\'); pos>=0; pos = this->path.find('\\'))
			this->path = this->path.replace(pos,1,"/");
#endif

	}

	Resource::~Resource()
	{
	}

	std::string Resource::getName()
	{
		std::string name;
		int posicion;
#ifdef WIN
		posicion = this->path.find_last_of('\\');
#else
		posicion = this->path.find_last_of('/');
#endif
		if (posicion>=0)
			name = this->path.substr(posicion+1);
		else
			name = name;
		return name;
	}

	void Resource::initialize()
	{
		this->mutex.lock();
		if (!this->initialized)
		{	
			this->load();
			this->initialized = true;
		}
		this->mutex.unlock();
	}
}